//函数类型接口：对方法传入的参数以及返回值进行约束  批量约束


//加密的函数类型接口  

// interface encrypt{
//     (key: string, value: string): string;
// }

// var md5: encrypt = function (key: string, value: string): string{
//     //模拟操作
//     return key + value;
// }

// console.log(md5('name', 'zhangsan'))





//可索引接口：数组、对象的约束 （不常用）

//ts定义数组的方式
/*
    var arr:number[]=[2222,3434343]
    var arr1:Array<string>=['111','222']
*/


//可索引接口 对数组的约束
// interface UserArr{
//     [index:number]:string
// }
// var arr: UserArr = ['3232323', '34343434']
// console.log(arr[0])

//可索引接口  对对象的约束
// interface UserObj{
//     [index:string]:string
// }
// var arr: UserObj = { name: '张三', age: '20' }
// console.log(arr)

//类类型接口：对类的约束 和 抽象类抽象方法有点相似
/*
    interface Animal{
        name:string;
        eat(val:string):void;
    }

    class Dog implements Animal{
        name: string;
        constructor(name: string) {
            this.name = name;
        }
        eat() {
            console.log(`${this.name}吃骨头`)
        }
    }
    var d = new Dog('小黑')
    d.eat();

    class Cat implements Animal{
        name: string;
        constructor(name: string) {
            this.name = name;
        }
        eat(food:string) {
            console.log(`${this.name}吃${food}`)
        }
    }


    var c = new Cat('小花')
    c.eat('小鱼');
*/

//接口扩展： 接口可以继承接口

interface Animal{
    eat(): void;
}
interface Person extends Animal{
    work(): void;
}
class Programmer{
    public name: string
    constructor(name: string) {
        this.name = name
    }
    coding(code: string) {
        console.log(`${this.name}${code}`)
    }
}
class Web extends Programmer implements Person{
    constructor(name: string) {
        super(name)
    }
    eat() {
        console.log(`${this.name}喜欢吃馒头`)
    }
    work() {
        console.log(`${this.name}在工作`)
    }
}
var a = new Web('小明')
a.eat()
a.work()
a.coding('写ts代码')